package org.jader.bolao;

import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.jader.bolao.beans.PropertyChangeListener;
import org.jader.bolao.classificationalgorithm.ClassifyByPoints;
import org.jader.bolao.classificationalgorithm.ClassifyByTotals;
import org.jader.bolao.classificationalgorithm.ClassifyByWins;

public class ClassificationFactory {
	private static Set<ClassificationAlgorithm> pca = new HashSet<ClassificationAlgorithm>();
	
	static {
		pca.add(new ClassifyByPoints());
		pca.add(new ClassifyByTotals());
		pca.add(new ClassifyByWins());
	}
	
	private ClassificationFactory() {}
	
	public static Set<ClassificationAlgorithm> possibleClassificationAlgorithms() {
		return pca;
	}
	
	public static ClassificationAlgorithm get(Class<? extends ClassificationAlgorithm> c) {
		Iterator <ClassificationAlgorithm> it = ClassificationFactory.possibleClassificationAlgorithms().iterator();
		while (it.hasNext()) {
			ClassificationAlgorithm ca = it.next();
			if (ca.getClass().equals(c)) return ca;
		}
		return null;
	}
	
	public static void addPropertyChangeListener(PropertyChangeListener pcl) {
		Iterator<ClassificationAlgorithm> it = pca.iterator();
		while (it.hasNext()) it.next().addPropertyChangeListener(pcl);
	}
	
}
